package com.osce.basic.controller;

import com.csce.domain.entity.basic.BasicSchoolYear;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.basic.IBasicSchoolYearService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学年表Controller
 *
 * @author zzx
 * @since 2023-07-18
 */
@RestController
@RequestMapping("/basic/school_year")
public class BasicSchoolYearController extends BaseController {

    @Resource
    private IBasicSchoolYearService basicSchoolYearService;

    /**
     * 查询学年表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:school_year:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicSchoolYear basicSchoolYear) {
        startPage();
        List<BasicSchoolYear> list = basicSchoolYearService.selectBasicSchoolYearList(basicSchoolYear);
        return getDataTable(list);
    }

    /**
     * 导出学年表列表
     */
    @PreAuthorize("@ss.hasPermi('basic:school_year:export')")
    @Log(title = "学年表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicSchoolYear basicSchoolYear) {
        List<BasicSchoolYear> list = basicSchoolYearService.selectBasicSchoolYearList(basicSchoolYear);
        ExcelUtil<BasicSchoolYear> util = new ExcelUtil<BasicSchoolYear>(BasicSchoolYear.class);
        util.exportExcel(response, list, "学年表数据");
    }

    /**
     * 获取学年表详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:school_year:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basicSchoolYearService.selectBasicSchoolYearById(id));
    }

    /**
     * 新增学年表
     */
    @PreAuthorize("@ss.hasPermi('basic:school_year:add')")
    @Log(title = "学年表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicSchoolYear basicSchoolYear) {
        return toAjax(basicSchoolYearService.insertBasicSchoolYear(basicSchoolYear));
    }

    /**
     * 修改学年表
     */
    @PreAuthorize("@ss.hasPermi('basic:school_year:edit')")
    @Log(title = "学年表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicSchoolYear basicSchoolYear) {
        return toAjax(basicSchoolYearService.updateBasicSchoolYear(basicSchoolYear));
    }

    /**
     * 删除学年表
     */
    @PreAuthorize("@ss.hasPermi('basic:school_year:remove')")
    @Log(title = "学年表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basicSchoolYearService.deleteBasicSchoolYearByIds(ids));
    }
}
